<?php echo \think\facade\View::fetch("public/header"); ?>

<div id="right">
    <div id="content">
        <div id="breadcrumb">
            <a href="/admin/article/index">首页</a> &gt;
            <a href="/admin/article/index">文章管理</a> &gt;
            <a href="/admin/article/index">文章列表</a>
        </div>

        <div id="choose_div">
            <!--                                <button id="choose-all" class="btn">全选</button>-->
            <!--                                <a href="#">删除选中任务</a>-->
            <a href="/admin/article/add/" class="add">增加文章</a>
        </div>

        <table id="list" class="list">
            <tr>
                <th></th>
                <th>Id</th>
                <th>标题</th>
                <th>分类</th>
                <th width="25%">简介</th>
                <th>发表时间</th>
                <th>修改时间</th>
                <th>操作</th>
            </tr>
            <?php foreach ($articleList as $row): ?>
                <tr>
                    <td><input type="checkbox"/></td>
                    <td><?php echo $row['article_id']; ?></td>
                    <td><?php echo $row['article_title']; ?></td>
                    <td><?php echo $row['category_name']; ?></td>
                    <td><?php echo $row['intro']; ?></td>
                    <td><?php echo date("Y-m-d H:i:s", $row['add_time']); ?></td>
                    <td><?php echo date("Y-m-d H:i:s", $row['update_time']); ?></td>
                    <td>
                        <a href="/admin/article/edit/article_id/<?php echo $row['article_id']; ?>/">编辑</a>
                        <a href="/admin/article/delete/article_id/<?php echo $row['article_id']; ?>/">删除</a>
                    </td>
                </tr>
            <?php endforeach; ?>
        </table>
    </div>
</div>

<script>
    // let xmlHttp = new XMLHttpRequest();
    // xmlHttp.onreadystatechange = function () {
    //     if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
    //         let data = JSON.parse(xmlHttp.responseText);
    //         if (data.status > 0) {
    //             window.alert("出现错误：" + data.message);
    //         } else {
    //             // 获取表格的内的html内容
    //             let listHtml = document.getElementById('list').innerHTML;
    //
    //             // 遍历文章数据，拼接表格html代码
    //             let articleData = data.data.articleData;
    //             for (let i in articleData) {
    //                 console.log(articleData[i]);
    //                 let trString = '<tr>';
    //                 trString += '<td><input type="checkbox"/></td>';
    //                 trString += '<td>' + articleData[i].article_id + '</td>';
    //                 trString += '<td>' + articleData[i].article_title + '</td>';
    //                 trString += '<td>' + articleData[i].category_name + '</td>';
    //                 trString += '<td>' + articleData[i].intro + '</td>';
    //                 trString += '<td>' + articleData[i].add_time + '</td>';
    //                 trString += '<td>' + articleData[i].update_time + '</td>';
    //                 trString += '<td></td>';
    //                 trString += '</tr>';
    //
    //                 listHtml += trString;
    //             }
    //
    //             // 替换表格内容为相应的html
    //             document.getElementById('list').innerHTML = listHtml;
    //         }
    //     }
    // };
    // xmlHttp.open("GET", "/api/article/index/", true);
    // xmlHttp.send();
</script>

<?php echo \think\facade\View::fetch("public/footer"); ?>

